﻿
namespace CARE.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria;
    using System.Web.Ria.Data;
    using System.Web.DomainServices;
    using System.Data.Linq;
    using System.Web.DomainServices.LinqToSql;
    using CARE.Web.db;


    // Implements application logic using the DataBaseClassesDataContext context.
    // TODO: Add your application logic to these methods or in additional methods.
    [EnableClientAccess()]
    public class DataProvider : LinqToSqlDomainService<DataBaseClassesDataContext>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Disease> GetDiseases()
        {
            return this.Context.Diseases;
        }

        public void InsertDisease(Disease disease)
        {
            this.Context.Diseases.InsertOnSubmit(disease);
        }

        public void UpdateDisease(Disease currentDisease)
        {
            this.Context.Diseases.Attach(currentDisease, this.ChangeSet.GetOriginal(currentDisease));
        }

        public void DeleteDisease(Disease disease)
        {
            this.Context.Diseases.Attach(disease);
            this.Context.Diseases.DeleteOnSubmit(disease);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Edge> GetEdges()
        {
            return this.Context.Edges;
        }

        public void InsertEdge(Edge edge)
        {
            this.Context.Edges.InsertOnSubmit(edge);
        }

        public void UpdateEdge(Edge currentEdge)
        {
            this.Context.Edges.Attach(currentEdge, this.ChangeSet.GetOriginal(currentEdge));
        }

        public void DeleteEdge(Edge edge)
        {
            this.Context.Edges.Attach(edge);
            this.Context.Edges.DeleteOnSubmit(edge);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Form> GetForms()
        {
            return this.Context.Forms;
        }

        public void InsertForm(Form form)
        {
            this.Context.Forms.InsertOnSubmit(form);
        }

        public void UpdateForm(Form currentForm)
        {
            this.Context.Forms.Attach(currentForm, this.ChangeSet.GetOriginal(currentForm));
        }

        public void DeleteForm(Form form)
        {
            this.Context.Forms.Attach(form);
            this.Context.Forms.DeleteOnSubmit(form);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<FormTemplate> GetFormTemplates()
        {
            return this.Context.FormTemplates;
        }

        public void InsertFormTemplate(FormTemplate formTemplate)
        {
            this.Context.FormTemplates.InsertOnSubmit(formTemplate);
        }

        public void UpdateFormTemplate(FormTemplate currentFormTemplate)
        {
            this.Context.FormTemplates.Attach(currentFormTemplate, this.ChangeSet.GetOriginal(currentFormTemplate));
        }

        public void DeleteFormTemplate(FormTemplate formTemplate)
        {
            this.Context.FormTemplates.Attach(formTemplate);
            this.Context.FormTemplates.DeleteOnSubmit(formTemplate);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Image> GetImages()
        {
            return this.Context.Images;
        }

        public void InsertImage(Image image)
        {
            this.Context.Images.InsertOnSubmit(image);
        }

        public void UpdateImage(Image currentImage)
        {
            this.Context.Images.Attach(currentImage, this.ChangeSet.GetOriginal(currentImage));
        }

        public void DeleteImage(Image image)
        {
            this.Context.Images.Attach(image);
            this.Context.Images.DeleteOnSubmit(image);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Net> GetNets()
        {
            return this.Context.Nets;
        }

        public void InsertNet(Net net)
        {
            this.Context.Nets.InsertOnSubmit(net);
        }

        public void UpdateNet(Net currentNet)
        {
            this.Context.Nets.Attach(currentNet, this.ChangeSet.GetOriginal(currentNet));
        }

        public void DeleteNet(Net net)
        {
            this.Context.Nets.Attach(net);
            this.Context.Nets.DeleteOnSubmit(net);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Node> GetNodes()
        {
            return this.Context.Nodes;
        }

        public void InsertNode(Node node)
        {
            this.Context.Nodes.InsertOnSubmit(node);
        }

        public void UpdateNode(Node currentNode)
        {
            this.Context.Nodes.Attach(currentNode, this.ChangeSet.GetOriginal(currentNode));
        }

        public void DeleteNode(Node node)
        {
            this.Context.Nodes.Attach(node);
            this.Context.Nodes.DeleteOnSubmit(node);
        }
    }
}


